<?php
class mcz_Session
{
	private $user;
	private $auth;
	public function __construct()
	{
		$this->user = new mcz_User();
		if(!mcz_USE_AUTH)
		{
			$this->user = mcz_User::findOneByLogin('anonymous');
			$this->auth = true;
		}
		else
		{
			$this->auth = false;
		}
	}

	public function can($doshit)
	{
		if(mcz_USE_AUTH)
		{
			return $this->user->can($doshit);
		}
		return true;
	}

	public function isAuth()
	{
		if(!mcz_USE_AUTH)
		{
			return true;
		}
		return $this->auth;
	}

	public function login($user, $pass)
	{
		$res = mcz_DB::getInstance()
				->fetch('* from mcz_User where login = ? and password = ? and active = 1',
						array($user, sha1($pass)));
		if($res)
		{
			$this->auth = true;
			$this->user = new mcz_User($res[0]);
			return true;
		}
		return false;
	}

	public function __get($key)
	{
		if($key == 'login')
		{
			return $this->user->login;
		}
		if($key == 'id')
		{
			return $this->user->id;
		}
	}
}